using UnityEngine;

public class RingMeshAnim : MeshAnimBase
{
    private RingMesh[] _ringMeshes;
    private float[] _endAngles;
    
    protected override void Init()
    {
        _ringMeshes = gameObject.GetComponentsInChildren<RingMesh>();
        _count = _ringMeshes.Length;
        _endAngles = new float[_count];
        for (int i = 0; i < _count; i++)
        {
            _endAngles[i] = _ringMeshes[i].m_AngleEnd;
        }
    }

    protected override void SetBeginState()
    {
        for (var i = 0; i < _count; i++)
        {
            _ringMeshes[i].m_AngleBegin = 0;
            _ringMeshes[i].AngleEnd = 0;
        }
    }

    protected override void PlayForwardAnimation()
    {
        for (var i = 0; i < _count; i++)
        {
            var duration = Random.Range(m_minDuration, m_maxDuration);
            var delay = Random.Range(m_minDelay, m_maxDelay);
            _ringMeshes[i].DoAnim(_endAngles[i], duration, delay);
        }
    }

    protected override void PlayBackwardAnimation()
    {
        for (var i = 0; i < _count; i++)
        {
            var duration = Random.Range(m_minDuration, m_maxDuration);
            var delay = Random.Range(m_minDelay, m_maxDelay);
            _ringMeshes[i].DoAnim(0f, duration, delay);
        }
    }
}
